//
//  SZMainViewController.m
//  Weibo
//
//  Created by Zahi on 2017/7/22.
//  Copyright © 2017年 Zahi. All rights reserved.
//

#import "SZMainViewController.h"
#import "SZNavigationController.h"
#import "SZTabBar.h"

@interface SZMainViewController ()

@end

@implementation SZMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setValue:[SZTabBar new] forKey:@"tabBar"];
    
    NSMutableArray *navCtls = [NSMutableArray array];
    
    [navCtls addObject: [self addChildViewController:@"SZHomeTableViewController" title:@"首页" image:@"tabbar_home"]];
    [navCtls addObject: [self addChildViewController:@"SZMessageTableViewController" title:@"消息" image:@"tabbar_message_center"]];
    
    [navCtls addObject:[self addChildViewController:@"SZDiscoverTableViewController" title:@"发现" image:@"tabbar_discover"]];
    [navCtls addObject:[self addChildViewController:@"SZMineTableViewController" title:@"我的" image:@"tabbar_profile"]];

    self.viewControllers = navCtls;
    
}

- (SZNavigationController *)addChildViewController:(NSString *)className title:(NSString *)title image:(NSString *)imageName
{
    UIViewController *vc = [[NSClassFromString(className) alloc] init];
    
    vc.title = title;
    
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    
    UIImage *selectedImg = [UIImage imageNamed:[imageName stringByAppendingString:@"_selected"]];
    vc.tabBarItem.selectedImage = [selectedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor], NSFontAttributeName : [UIFont systemFontOfSize:12]} forState:UIControlStateSelected];
    SZNavigationController *nav = [[SZNavigationController alloc] initWithRootViewController:vc];
    
    return nav;
    
}

@end
